package com.fs.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fs.mapper.UserMapper;
import com.fs.pojo.User;
import com.fs.service.UserService;
import com.fs.vo.Meta;
import com.fs.vo.ResponseData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author yyds
 * @fileName UserServiceImpl
 * @date 2024/9/10 16:06
 * @description
 **/
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public ResponseData<User> login(User user) {
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(User::getUName, user.getUName());
        ResponseData<User> responseData = new ResponseData<>();
        User u = userMapper.selectOne(wrapper);
        String msg;
        System.out.println(user.getUName()+"/"+user.getPassword());
        Integer status;
        if (u == null) {
            status = 100;
            msg = "用户不存在";
        } else {
            if (u.getPassword().equals(user.getPassword())) {
                status = 200;
                msg = "登录成功";
            } else {
                status = 100;
                msg = "密码错误";
            }
        }
        Meta meta = new Meta(status, msg);
        responseData.setMeta(meta);
        responseData.setData(u);
        return responseData;
    }

    @Override
    public boolean register(User user) {
        return userMapper.insert(user) > 0;
    }
}
